#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
int int_cmp(const void* e1, const void* e2)
{
	return (*(int*)e1 - *(int*)e2);
}
int main()
{
	int arr[15] = { 2,5,4,9,13,15,26,49,56,32,51,3,1,88,62 };
	qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), int_cmp);
	int i = 0;
	for (i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)                          //用qsort函数来给整形数据排序
	{
		printf("%d ", arr[i]);
	}
	return 0;
}                                                                     
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
int float_cmp(const void* e1, const void* e2)
{
	return (*(float*)e1 - *(float*)e2);
}
int main()
{
	float arr[15] = { 2.5f,5.3f,4.9f,9.3f,13.7f,15.6f,26.7f,49.9f,56.6f,32.1f,51.2f,3.7f,1.8f,88.9f,62.5f };
	qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof(float), float_cmp);
	int i = 0;
	for (i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)                   //用qsort函数来给单精度浮点型（float）数据排序
	{
	{
		printf("%.1f\n", arr[i]);
	}
	return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct Stu
{
	char name[20];
	int age;
};
int cmp_stu_by_name(const void* e1, const void* e2)
{
	return strcmp((*(struct Stu*)e1).name, (*(struct Stu*)e2).name);
}
int cmp_stu_by_age(const void* e1, const void* e2)
{
	return ((*(struct Stu*)e1).age - (*(struct Stu*)e2).age);
}
void test1()
{
	struct Stu a[] = { { "zhangsan",15 },{ "lisi",19 } ,{ "wangmazi",29 } ,{ "zhaowu",25 } ,{ "liuliu",36 } };        //用qsort函数分别按名字，年龄大小来给结构体数据排序
	int sz = sizeof(a) / sizeof(a[0]);
	qsort(a, sz, sizeof(a[0]), cmp_stu_by_name);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s ", a[i].name);
	}
}
void test2()
{
	struct Stu a[] = { { "zhangsan",15 },{ "lisi",19 } ,{ "wangmazi",29 } ,{ "zhaowu",25 } ,{ "liuliu",36 } };
	int sz = sizeof(a) / sizeof(a[0]);
	qsort(a, sz, sizeof(a[0]), cmp_stu_by_age);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", a[i].age);
	}
}
int main()
{
	test1();
	test2();
	return 0;
}